<?php
/** $Id: default_form.php 11917 2009-05-29 19:37:05Z ian $ */
defined( '_JEXEC' ) or die( 'Restricted access' );
	$user = JFactory::getUser();
?>
 <?php
// category brugerbetingelserne tilmeld firma
$items = getArticles(34);
$slug = $items[0]->id.':'.$items[0]->alias;
$catslug =$items[0]->catid ? $items[0]->catid .':'.$items[0]->category_alias : $items[0]->catid;
require_once JPATH_SITE.'/components/com_content/helpers/route.php';
$readmore = JRoute::_(ContentHelperRoute::getArticleRoute($slug, $catslug));


$db =& JFactory::getDBO();
  $query = "SELECT count(*) as total FROM #__uworks WHERE state != -2 AND userid = ".$user->id." AND jobid = ".$this->row->id;												 
  $db->setQuery( $query );
  $rowcountuser = $db->loadObject();
	
  $query = "SELECT count(*) as total FROM #__uworks WHERE state != -2 AND jobid=".$this->row->id;
  $db->setQuery( $query );
  $rowcount = $db->loadObject();
												  
												  
												  
?>
<div class="task-detail">
    <h2 class="task-title">ID. <?php echo $this->row->id;?> <?php echo $this->row->title;?></h2>
    <p class="date">(Oprettet d. <?php echo JHtml::_('date', $this->row->created , JText::_('DATE_FORMAT_LC6')) ;?>, Privat Kunde)</p>
    <form action="<?php echo JRoute::_( 'index.php?view=myjobs' );?>" method="post" name="addjobform" id="addjobform">
    <div class="content-view">
        <p class="desc"><?php echo $this->row->description;?></p>
        <p class="kunde-info">
            Kunden estimerer prisen til at være: <?php echo $this->row_pris->title; ?><br/>
            Opgaven ønskes afsluttet: <?php echo JHtml::_('date', $this->row->deadline , JText::_('DATE_FORMAT_LC6')) ;?><br/>
            Landsdel: <?php echo $this->land; ?>
            
            <?php
				$db =& JFactory::getDBO();
				$query = 'SELECT count(*) as "viewjobtotal" FROM #__uworks where userid = '.$user->id.' and jobid='.$this->row->id;
				
				$db->setQuery( $query );
				$viewjob = $db->loadObject();
				if(isset($viewjob) && $viewjob->viewjobtotal >0) {
            ?>
            <br/><br/><span style="color:#008E00;">Du har allerede købt denne opgave og kan finde den samt kundens kontaktoplysninger under
fanen “Mine opgaver”.</span>
			<?php } ?>
        </p>
        
        <?php
        if($rowcountuser->total==0 && $rowcount->total <=2 && 	$this->row->close_project_bid==0)
		{
			 
			  	 $infokkunden = getArticles(50); 
				
			     
		?>
        <h3 class="contact-info"><span class="fll">Kundens kontaktoplysninger?</span><span class="info-icon fll" title="<?php echo  $infokkunden[0]->introtext;?>"></span></h3>
        <p class="input-set"><label class="check-box"><input  id="btncbox" name="btncbox"  class="check-box" type="checkbox" />Jeg accepterer <a href="<?php echo $readmore;?>" target="_blank">brugerbetingelserne.</a></label></p>
        <p class="point"><span class="point-num fll"><?php echo $this->row->point;?> point</span>
        <?php
			 // $user =& JFactory::getUser();
			  $db =& JFactory::getDBO();
			  $query = "SELECT amount_money FROM #__users WHERE ID= ".$user->id;
			  $db->setQuery( $query );
			  $rowuser = $db->loadObject();		
			  if($rowuser->amount_money > $this->row->point) 
			  {											  
        ?>
       			 <a class="button buy-contact fll" style="cursor:pointer;" onclick="$('#addjobform').submit();">Køb kontaktoplysninger</a>
        	<?php } else {
				?>
                 <a class="button buy-contact fll" style="cursor:pointer;" onclick="infoamrion();">Køb kontaktoplysninger</a>
                <?php
			}
			?>
        </p>
         <?php
			}
			?>
     </div>
   	    <input type="hidden" name="option" value="com_jobs" />
        <input type="hidden" name="id" value="<?php echo $this->row->id;?>" />       
        <input type="hidden" name="view" value="myjobs" />        
        <input type="hidden" name="task" value="addtomyjob" />
        <?php echo JHTML::_( 'form.token' ); ?>
     </form>
</div>



<?php
/** $Id: default_form.php 11917 2009-05-29 19:37:05Z ian $ */
	$input_btncbox = JText::_( 'Venligst accepterer brugerbetingelserne' );		
	$app = JFactory::getApplication();
	$template = JURI::base() . 'templates/' . $app->getTemplate();
?>
<script type="text/javascript">
	$(function(){
		$(".info-icon").tipTip();
	});
</script>
<script type="text/javascript">

function infoamrionSuccess() {
	$('#alert').html('Opgaven er nu købt og kan findes <br>under “Mine opgaver”');
	$('#backoverlay').show();
	$('#show_popup').show();
}
function infoamrion() {
	$('#alert').html('Du har ikke point nok for at købe kontaktoplysningerne');
	$('#backoverlay').show();
	$('#show_popup').show();
}
$(document).ready(function($) {	
	   	  
		$.validator.addMethod("defaultInvalid", function(value, element) 
		{
			//alert(element.value);
		 switch (element.value) 
		 {
			
		 	 case "Navn": 	if (element.name == "name") return false;
			 case "Telefon": 	if (element.name == "subject") return false;
			 //case "Email": 	if (element.name == "email") return false;
			 case "Skriv din besked her": 	if (element.name == "text") return false;
			 default:
			 return true;
			 break;

		 }
		});
		$("#addjobform").validate(
			{
				errorPlacement: function(error, element) {			
			},
			invalidHandler: function(form, validator) {
			  var errors = validator.numberOfInvalids();
			if (errors) {
                $('#alert').html(validator['errorList'][0]['message']);
    			$('#backoverlay').show();
    			$('#show_popup').show();
            	$('#f_focus').html(validator['errorList'][0]['element'].name);
				validator['errorList'][0]['element'].focus();
			  } else {
				 //infoamrionSuccess();
			  }
			},
			rules: {
                btncbox : "required",				
                
			},
			messages: {
                btncbox: "<?php echo $input_btncbox; ?>",				   				
			}/*,
      		submitHandler: function() { 
				$("#TB_closeWindowButton").click();
			 	infoamrionSuccess();
			}*/
		});
        close_popup=function(){		
    		var fel=$('#f_focus').html();
            $('#backoverlay').hide();
    		$('#show_popup').hide();
    		$('#' + fel ).focus();			
      };
      reset_form=function(){
            document.forms[0].reset()
      };
      
	});
</script>
<style>
    img{border: none;}
    .bg_alert{ width:270px; height:115px; background:url("<?php echo $template ?>/img/bg_alert.png") no-repeat top left; margin:0px auto; padding:15px 0px 0px 83px; color:#000;}
    .m35l{ margin-left:35px;}
</style>
<div id="dialog" style="display:none; position: fixed; top: 10%; left: 35%; z-index:10002;"></div>
<div class="bg_alert" id="show_popup" style="display:none; position: fixed; top: 35%; left: 50%; z-index:10003; margin-left:-140px;">
    <span id="f_focus" style="display:none;"></span>
    <div style="margin:0; padding-top:10px; min-height:60px;" id="alert"></div>
    <div style="padding-left: 40px;"><a href="javascript:void(0);" onclick="close_popup();"><img src="<?php echo $template ?>/img/bt_luk.png" alt="" /></a></div>
</div>
<div style="display: none;position: fixed; top: 0;left: 0;width: 100%;height: 100%;background-color: #000000;z-index:10002;-moz-opacity: 0.8;opacity:.80;filter: alpha(opacity=80);" id="backoverlay"></div>	